<template>
  <div class="login">
    <!-- 底部的背景轮播图 外层高度100vh，swiper height:100% 继承-->
    <swiper :options="swiperOption" style="height:100%">
      <swiper-slide class="swiper-slide" v-for="item in imgArr" :key="item.id">
        <img :src="imgUrl + item.url" alt=""> 
      </swiper-slide>
    </swiper>
    <!-- 上层的轮播图 是网页高度100vh的  height: 77%;width: 91%; -->
    <div class="login-area" >
      <!-- 左侧all-height--100%继承 -->
      <a-row class="all-height">
        <a-col span="17" class="all-height">
          <swiper :options="swiperOption" class="all-height">
            <swiper-slide class="swiper-slide" v-for="item in imgArr" :key="item.id">
              <img :src="imgUrl + item.url" alt=""> 
            </swiper-slide>
            <div class="swiper-pagination"  slot="pagination"></div>   
          </swiper>
        </a-col>
        <!-- 左侧100%继承 -->
        <a-col span="7"  class="right">
          <div class="title">
              {{userStatus===1?'欢迎登录':userStatus===2?'忘记密码':'修改成功'}}
          </div>
          <!-- 登录 -->
          <div v-if="userStatus === 1">
            <div class="info-list">
              <div class="self">
                <span style="font-size:1rem">账号</span>
                <input style="width:50%;" v-model="name" />
              </div>
            </div>
            <div class="info-list">
              <div class="self">
                <span>密码</span>
                <input style="width:50%;" v-model="password" type="password" />
              </div>
            </div>
            <div class="info-list">
              <div class="self" style="position:relative;">
                <span>验证码</span>
                <input style="width:50%;" v-model="valid"/>
                <!-- 验证组件 -->
                 <img 
                  :src="captcha_imgage" 
                  class="captcha-img" 
                  @click="getImgVild"
                  alt=""
                 >
                <!-- <valid-code 
                  :value.sync="validCode"
                  @reset="resetValid"
                  width="6.875rem"
                  height="2.8125rem"
                  style="position:absolute;right:0;bottom:0;" 
                ></valid-code> -->
                <!-- 验证码错误提示 -->
                <!-- <div class="valid-txt" v-if="isValidTxt">请输入正确的验证码</div> -->
              </div>
            </div>
          </div>
          <!-- 修改 -->
          <div v-else-if="userStatus === 2">
            <div class="info-list">
              <div class="self">
                <span>账号</span>
                <input style="width:50%;" />
              </div>
            </div>
            <div class="info-list" style="position:relative;">
              <div class="self up-valid">
                <span>验证码
                </span>
                <input style="width:50%;" />
                <span  class="get-valid" @click="getCode">
                  获取验证码 
                  <span v-if="count > 0">({{count + 's'}})</span> 
                </span>
              </div>
            </div>
            <div class="info-list">
              <div class="self">
                <span>新密码</span>
                <input style="width:50%;" />
              </div>
            </div>
            <div class="info-list">
              <div class="self">
                <span>确认密码</span>
                <input style="width:50%;" />
              </div>
            </div>
          </div>
          <!-- 修改成功 -->
          <div v-else>
            <img src="" alt="">
            <div>您已成功修改密码请直接登录</div>
          </div>
          <!-- 立即登录 -->
          <div class="info-list" style="margin-top:5rem;"> 
            <a-button 
            style="width:100%;" 
            size="large" 
            type="primary"
            @click="userStatus===1? login(): userStatus===2? upUser(): toIndex()"
            >
              {{userStatus===1?'立即登录':userStatus===2?'确认修改':'前往登录'}}
            </a-button> 
          </div>
          <!-- 去登录 -->
          <div v-if="userStatus === 2" class="go-login">去登录</div>
          <div 
            v-if="userStatus === 1" 
            class="info-list forget-pass"
            @click="forgetPass"
          >忘记密码</div>
          <div class="introduct">HA网络技术有限公司</div>
        </a-col>

      </a-row>
    </div>
  </div>
</template>
<script>
// import ValidCode from './component/ValidCode'
import { apiLogin, apiBanner, apiImgVild, apiSmsVild } from '@/utils/api.js'
import '@/assets/css/common.less';
import BASE from '@/base'
export default {
  components: {
    // ValidCode
  },
  data() {
    return {
      imgUrl: BASE.imgUrl,
      // 用户名
      name:'18322812202',
      // 密码
      password:'',
      // 前端生成验证码
      validCode:'',
      // 前端输入验证码
      valid:'',
      // 验证码出错提示
      isValidTxt: false,
      // 后端生成验证码
      captcha_key:'',
      // 后端生成验证码图片
      captcha_imgage: '',
      warnInfo: '',
      count: '',
      timer: null,
      // 用户状态
      userStatus: 1,
      slide: [1, 2, 3, 4, 5],
      imgArr: [],
      //设置属性
      swiperOption: {
        fadeEffect: {
          crossFade: true,
        },
        //显示分页
        pagination: {
          el: '.swiper-pagination',
          clickable: false //允许分页点击跳转
        },
        //自动轮播
        autoplay: {
          delay: 4000
        },
        //开启循环模式
        loop: true,
        //开启鼠标滚轮控制Swiper切换
        mousewheel: true
      }
    }
  },
  watch: {
    // 监听验证码
    valid: function(val)  {
      if(val.length >= 4) {
        if(val.toLowerCase() !== this.validCode.toLowerCase()) {
          this.isValidTxt = true;
        }else{
          this.isValidTxt = false;
        }
      }else{
        this.isValidTxt = false;
      }
    },
    // item() {
    //   return 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1580991056369&di=85d4ce24e88342bb95f7d55199e59fa2&imgtype=0&src=http%3A%2F%2Fimg.pconline.com.cn%2Fimages%2Fupload%2Fupc%2Ftx%2Fwallpaper%2F1207%2F16%2Fc0%2F12347336_1342406678053.jpg'
    // }
  },
  mounted() {
    window.console.log(234)
    this.getBanner();
    this.getImgVild();
    
  },
  methods: {
    imgbtn(e) {
      window.console.log('imgbtn',e)

    },
    getCode(){
      const TIME_COUNT = 60;
      if (!this.timer) {
      this.count = TIME_COUNT;
      this.timer = setInterval(() => {
      if (this.count > 0 && this.count <= TIME_COUNT) {
        this.count--;
        } else {
        clearInterval(this.timer);
          this.timer = null;
          }
        }, 1000)
      }
      // 短信验证接口
      apiSmsVild(this.name).then(res => {
        window.console.log('eeeeeeeeeeeeeeeeeeee')

        window.console.log('短信。。。。。。',res)
      })
    },
    // 点击忘记密码
    forgetPass() {
      this.userStatus = 2;
    },
    // 关闭警告框
    warnClose() {
      this.isWarnShow = false;
    },
    // 登录
    login() {
    window.console.log('eeeeeeeeeeeeeeeeeeee')

      window.console.log('login',this.name, this.password, this.validCode)
      if(!this.name) {
        this.$message.warning('请输入用户名');
        return false;
      }
      if(!this.password) {
        this.$message.warning('请输入密码');
        return false;
      }
      if(!this.valid) {
        this.$message.warning('请输入验证码');
        return false;
      }
      // if(this.valid.toLowerCase() !== this.validCode.toLowerCase()) {
      //   this.$message.error('验证码输入有误');
      //   return false;
      // }
      apiLogin(this.name,this.password,this.valid,this.captcha_key).then((res) => {
        if(res.code === 10000) {
          this.$message.success(res.message);
          // 保存token
          sessionStorage.setItem('token',res.data.token)
          this.$router.replace('/')
        }else{
          this.$message.error(res.message);
        }

      }).catch(() => {
        // window.console.log('err........', err)
        this.$message.error('登录账号 不存在');
        return false;
      })

    },
    // 验证码 
    getImgVild() {
      // 刷新验证码，input内容为空
      this.valid = '';
      apiImgVild().then(res => {
        if(res.code === 10000) {
          // 验证码 
          this.captcha_key = res.data.captcha_key;
          // 验证图片
          this.captcha_imgage = res.data.captcha_imgage;
        }

      }) 
    },
    // banner列表
    getBanner() {
      apiBanner(3).then(res => {
        if(res.code === 10000) {
          // 验证码 
          this.imgArr = res.data;
        }
      })
    },
    // 去修改
    upUser() {
      this.userStatus = 3;
    },
    toIndex() {
      this.userStatus = 1;
    }
  }
}
</script>
<style lang="less" scoped>
/deep/ .swiper-pagination-bullet {
  width: 50px;
  height: 5px;
  border-radius: 16px;
  background:#3C556F;
}
/deep/ .swiper-pagination-bullet-active {
  width: 50px;
  height: 5px;
  border-radius: 16px;
  background:#ffffff
}
/deep/ .swiper-pagination {
  text-align: left;
  padding-left: 40px;
  box-sizing: border-box;
  padding-bottom: 15px;
}

.login {
  font-size: 16px;
  position: relative;
  input {
    border: none;
    outline: none;
  }
  .swiper-slide {
    width: 100%;
    height: 100%;
    font-size: 50px;
    text-align: center;
    background-color: #f4f4f4;
    img {
      width: 100%;
      height: 100%;
    }
  }
  height: 100vh;
  display: flex;
  align-items: center;
  &-area {
    position: absolute;
    height: 77%;
    width: 91%;
    margin: auto;
    top: 0;
    left: 0;
    bottom: 0;
    right: 0;
    background: #ffffff;
    box-shadow: 0 5px 20px 0 rgba(0, 0, 0, 0.2);
    z-index: 9;
    .right {
      height: 100%;
      // border:1px solid red;
      .introduct {
        width: 100%;
        text-align: center;
        position: absolute;
        bottom: 28px;
      }
    }
    .title {
      text-align: center;
      color: #666666;
      font-size: 28px;
      margin-top: 102px;
      padding-bottom: 12px;
    }
    .info-list {
      margin-top: 42px;
      padding: 0 65px;
      .valid-txt{
        position:absolute;
        left:0;
        bottom:-20px;
        font-size: 13px;
        color:red;
      }
      .captcha-img{
        position:absolute;
        right:0;
        bottom:0;
        width:6.875rem;
        height:2.8125rem
      }
      .up-valid {
        width: calc(100% - 125px);
        .get-valid {
          position:absolute;
          right:40px;
          bottom:0;
          border:1px solid #358CF0;
          padding:8px 11px;
          font-size:12px;
          color:#358CF0;
          border-radius: 5px;
        }
      }
      .self {
        border-bottom: 1px solid #E7E7E7;
        padding-bottom: 13px;
        box-sizing: border-box;
        span {
          display: inline-block;
          // width: 50px;
          margin-right: 10px;
        }
      }
    }
    .go-login {
      margin-top: 15px;
      color: #358CF0;
      text-align: center;
    }
    .forget-pass {
      text-align: right;
      margin-top: 15px;
      color: #358CF0;
    }
  }
}
</style>